package com.qdxht.dispenser.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.qdxht.dispenser.base.BaseActivity;
import com.qdxht.dispenser.databinding.ActivityWebBinding;

public class WebActivity extends BaseActivity<ActivityWebBinding> {

    @Override
    protected ActivityWebBinding getBinding() {
        return ActivityWebBinding.inflate(getLayoutInflater());
    }

    public static void start(Context context,Integer type) {
        Intent intent = new Intent(context, WebActivity.class);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    WebView mWebView;

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
        mWebView = binding.webView;
        WebSettings webSettings = mWebView.getSettings();//获取webview设置属性
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//把html中的内容放大webview等宽的一列中
        webSettings.setJavaScriptEnabled(true);//支持js
        webSettings.setBuiltInZoomControls(false); // 显示放大缩小
        webSettings.setSupportZoom(false); // 可以缩放
        // 0用户协议 1隐私政策
        int type = getIntent().getIntExtra("type", 0);
        if (type == 0){
            setTitle("用户协议");
            mWebView.loadUrl("http://www.xiaodd.top/resources/user.html?t="+System.currentTimeMillis());
        } else {
            setTitle("隐私政策");
            mWebView.loadUrl("http://www.xiaodd.top/resources/privacy.html?t="+System.currentTimeMillis());
        }
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                System.out.println("mWebView: "+url);
                return false;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                System.out.println("mWebView: "+url);
                super.onPageFinished(view, url);
            }


        });
    }
}